﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Activities;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Anagramme.Activities.BusinessRules.Tests
{
    [TestClass]
    public class NotBusyNoErrorsActivityTests
    {
        [TestMethod]
        public void BusyReturnsFalse()
        {
            bool expected = false;
            IDictionary<string, object> actual = ExecuteWorkflow(true, false);

            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(expected, actual["ReturnValue"]);
        }

        [TestMethod]
        public void HasErrorsReturnsFalse()
        {
            bool expected = false;
            IDictionary<string, object> actual = ExecuteWorkflow(false, true);

            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(expected, actual["ReturnValue"]);
        }

        [TestMethod]
        public void NotBusyNoErrorsReturnsTrue()
        {
            bool expected = true;
            IDictionary<string, object> actual = ExecuteWorkflow(false, false);

            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(expected, actual["ReturnValue"]);
        }

        [TestMethod]
        protected IDictionary<string, object> ExecuteWorkflow(bool isBusy, bool hasErrors)
        {
            Dictionary<string, object> arguments = new Dictionary<string, object>()
            {
                { "IsBusy", isBusy },
                { "HasErrors", hasErrors }
            };

            NotBusyNoErrorsActivity activity = new NotBusyNoErrorsActivity();
            IDictionary<string, object> returnValue = WorkflowInvoker.Invoke(activity, arguments);

            return returnValue;
        }
    }
}
